import {createBrowserRouter,Navigate} from 'react-router-dom'
import { LOGIN_PATHNAME,REGISTE_PATHNAME,HOME_PATHNAME } from '../concats';

import AuthRouter from './AuthRouter';
//导入layout
import MainLayout from '../layouts/MainLayout'
import ManageLayout from '../layouts/ManageLayout'
import QuestionLayout from '../layouts/QuestionLayout';

//导入页面
import HomePages from '../pages/HomePages';
import NotFundPages from '../pages/NotFundPages';
import LoginPages from '../pages/LoginPages';
import RegistePages from '../pages/RegistePages';
import QuestionPages from '../pages/QuestionPages';
import StartPages from '../pages/StartPages';
import TrashPages from '../pages/TrashPages';

//编辑页面
import EditPages from '../pages/EditPages';
//统计页面
import StatPages from '../pages/StatPages';

export const isLoginORRegister = (path:string)=>{
    if([LOGIN_PATHNAME,REGISTE_PATHNAME].includes(path)){
        return true
    }else{
        return false
    }
}

export const isNeedLogin = (path:string) => {
    if([LOGIN_PATHNAME,REGISTE_PATHNAME,HOME_PATHNAME].includes(path)){
        return false
    }else{
        return true
    }
}

const routerConfig = createBrowserRouter([
    {
        path:'/',
        element:<MainLayout/>,
        children:[
            {
                path:'/',
                element:<HomePages/>
            },
            {
                path:'/login',
                element:<LoginPages/>
            },
            {
                path:'/registe',
                element:<RegistePages/>
            },
            {
                path:'/manage',
                element:<ManageLayout/>,
                children:[
                    {
                        path:'',
                        element:<Navigate  to = 'question'></Navigate >
                    },
                    {
                        path:'question',
                        element:<AuthRouter children={<QuestionPages/>}></AuthRouter>
                    },
                    {
                        path:'start',
                        element:<AuthRouter children={<StartPages/>}></AuthRouter>
                    },
                    {
                        path:'trash',
                        element:<AuthRouter children={<TrashPages/>}></AuthRouter>
                    },
                    {
                        path:"*",
                        element:<AuthRouter children={<NotFundPages/>}></AuthRouter>
                    }
                ]
            },
            {
                path:"*",
                element:<NotFundPages/>
            }
        ]
    },
    {
        path:'/question',
        element:<QuestionLayout/>,
        children:[
            {
                path:'edit/:id',
                element:<AuthRouter children={<EditPages/>}></AuthRouter>
            },
            {
                path:'stat/:id',
                element:<AuthRouter children={<StatPages/>}></AuthRouter>
            }
        ]
    }
])


export default routerConfig




